technovangelist / scripts / video script - working with ollama in vscode

video script - working with ollama in vscode

Check this out. Recently, the Ollama team released an official Node.js library for Ollama. You can find it here on GitHub. I’ll probably start building with it and the python equivalent soon, so I thought I would start playing around with it. Here I have imported Ollama and instantiated it. Then I call the chat endpoint with a simple system prompt and initial question. So now I want to print the output. This endpoint defaults to not streaming, so the response will just be a JSON blob with the output and some metrics about how it performed.

This is nice an easy, but we have to wait for the full response to be done before we see anything. Although it’s not faster or slower, the response feels faster when streaming because we start to see content sooner. So I can set stream to true and then try running it, and I get an error. That’s because setting stream to true sets the function to return an async generator instead of a JSON blob. And so we need to deal with it differently.

But did you notice that console.log and stream is true were typed for me? I just tabbed to accept the result. Which is pretty cool. You can see down here in the corner that I am not using Copilot, but rather Llama Coder.

I can even add a comment here describing what I want, and Llama Coder writes the code for me. It’s not always perfect, but it’s a good start. Now it’s printing each of the JSON blobs, and I just want the tokens. So I will add message.content to the console.log statement. And now I have each of the words, but they are on their own lines.

At this point, I need to have a conversation with my code and with an expert to figure out how to do this without newlines. And so that’s where Continue.dev comes in. I can select the code, then press command shift m and ask a question. “Is there an alternative to console.log that doesn’t add a newline?”. And it reminds me about process.stdout.write, which is perfect. So I start to type it in and Llama Coder knows what I want and allows me to tab to complete.

These two extensions for VS Code provide a pretty good alternative to copilot. They aren’t perfect, but they are completely free. And even better, they work when I have no connection to the Internet. You might think that rarely happens, but I live on an island near Seattle and to get to the mainland, I have to get on a ferry and there are no cell towers in the middle of Puget Sound. And the idea of just sitting there and enjoying the tremendous view when I can be buried in code is insanity.

So let’s take a brief look at what is involved in setting this up. Of course, you need Ollama installed and up and running. Go to ollama.ai to learn more about doing that. Next, install the Llama coder extension and take a look at the settings. I am using the model deepseek coder 1.3b q4. It’s nice and fast to work with and seems to do a good job. You should play around with which model works best for you. If a model has better answers but takes 5–10 seconds to generate, then I will never see those answers. Setting that model to use is really all you need to configure.

Next install Continue. There aren’t any settings up front that you need to set. But press command shift m on Mac or CTRL shift M on Windows and then down at the bottom you can select the model to use. I have stuck with CodeLlama, but you can add any model available with Ollama by just updating this JSON config file.

Take a look at the continue docs. There is another setting to disable telemetry so that it doesn’t try to use the Internet for anything. And there is a lot more that continue can do, so be sure to review the docs for that as well.

There are a few other VS Code extensions available, like Code GPT and Ollama Autocoder, but Llama Coder and Continue seem to work best for me. I’d also like to spend some time working with Cody from Sourcegraph. The CEO was pretty excited

What do you think? Have you replaced Copilot with something local? I would love to learn about your setup. Or if there is another config you would like to see, please let me know in the comments. Thanks so much for watching, goodbye.